
package views.panes;

import javax.swing.JPanel;
import view.pane.MainPane;
import views.MafiaFrame;
import views.screens.nightScreens.nightScreen1;

/**
 *
 * @author darkdev
 */
public class PlayersRegistrationPane extends javax.swing.JPanel {

    MafiaFrame gui;
    JPanel cancel;
    /** Creates new form PlayersRegistrationPane */
    public PlayersRegistrationPane( MafiaFrame gui,JPanel cancel) {
        initComponents();
        this.gui = gui;
        int nrPlayers=gui.settings.numberPlayers - gui.players.size();
        this.cancel = cancel;
        playersleft.setText("There are "+nrPlayers+" players left to register");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        newPlayer = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        startGame = new javax.swing.JButton();
        playersleft = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        newPlayer.setText("New Player");
        newPlayer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                newPlayerMouseClicked(evt);
            }
        });

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("All players have to create an account");

        startGame.setText("Start Game");
        startGame.setEnabled(false);
        startGame.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                startGameMouseClicked(evt);
            }
        });
        startGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startGameActionPerformed(evt);
            }
        });

        playersleft.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        playersleft.setText("There are ");

        jButton1.setText("Cancel");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(playersleft)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(newPlayer, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(startGame)))
                .addContainerGap(50, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, newPlayer, startGame});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, playersleft});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(playersleft)
                .addGap(71, 71, 71)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newPlayer)
                    .addComponent(jButton1)
                    .addComponent(startGame))
                .addContainerGap(96, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, newPlayer, startGame});

    }// </editor-fold>//GEN-END:initComponents

    private void newPlayerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_newPlayerMouseClicked
        // TODO add your handling code here:
        int nrPlayers=gui.settings.numberPlayers - gui.players.size();
        if(nrPlayers>0)
            gui.update(new EnlistmentPane(gui,this));       
    }//GEN-LAST:event_newPlayerMouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        gui.update(cancel);
    }//GEN-LAST:event_jButton1MouseClicked

    private void startGameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_startGameMouseClicked
        // TODO add your handling code here:
        gui.update(new nightScreen1(gui));
    }//GEN-LAST:event_startGameMouseClicked

    private void startGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startGameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_startGameActionPerformed

    public void userRegistered()
    {
        int nrPlayers=gui.settings.numberPlayers - gui.players.size();
        
         if(nrPlayers<=0)  {         
            newPlayer.setEnabled(false);
            startGame.setEnabled(true);
         }
        playersleft.setText("There are "+nrPlayers+" players left to register");
    } 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton newPlayer;
    private javax.swing.JLabel playersleft;
    private javax.swing.JButton startGame;
    // End of variables declaration//GEN-END:variables
}
